import 'package:flutter/material.dart';

main() {
  // runApp(ChooseView());
  runApp(RadioView());
}

class ChooseView extends StatefulWidget {
  const ChooseView({Key? key}) : super(key: key);

  @override
  _ChooseViewState createState() => _ChooseViewState();
}

class _ChooseViewState extends State<ChooseView> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('appbar'),
        ),
        body: MChoose(),
      ),
    );
  }
}

class MChoose extends StatefulWidget {
  const MChoose({Key? key}) : super(key: key);

  @override
  _MChooseState createState() => _MChooseState();
}

class _MChooseState extends State<MChoose> {
  bool? s = false;
  bool? s2 = false;
  bool? clt = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(
          height: 50,
        ),
        Row(
          children: [
            Checkbox(
              value: s,
              // shape: CircleBorder(),
              // activeColor: Colors.red,//勾选中的颜色
              fillColor: MaterialStateProperty.all(Colors.red), //颜色
              onChanged: (v) {
                setState(() {
                  s = v;
                });
              },
            ),
            Checkbox(
              value: s2,
              // shape: CircleBorder(),
              activeColor: Colors.red, //勾选中的颜色
              // fillColor: MaterialStateProperty.all(Colors.red),//颜色
              onChanged: (v) {
                setState(() {
                  s2 = v;
                });
              },
            )
          ],
        ),
        CheckboxListTile(
            value: clt,
            secondary: Icon(
              Icons.settings,
              size: 30,
              textDirection: TextDirection.rtl,
            ),
            title: Text("标题"),
            subtitle: Text('小标题'),
            onChanged: (value) {})
      ],
    );
  }
}

class RadioView extends StatefulWidget {
  const RadioView({Key? key}) : super(key: key);

  @override
  _RadioViewState createState() => _RadioViewState();
}

class _RadioViewState extends State<RadioView> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('按钮'),
        ),
        body: RadioBu(),
      ),
    );
  }
}

class RadioBu extends StatefulWidget {
  const RadioBu({Key? key}) : super(key: key);

  @override
  _RadioBuState createState() => _RadioBuState();
}

class _RadioBuState extends State<RadioBu> {
  var _sex;
  var _choose;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            Radio(
                value: 1,
                groupValue: _sex,
                onChanged: (v) {
                  setState(() {
                    _sex = v;
                  });
                }),
            Radio(
                value: 2,
                groupValue: _sex,
                onChanged: (v) {
                  setState(() {
                    _sex = v;
                  });
                }),
          ],
        ),
        SizedBox(
          height: 10,
        ),
        RadioListTile(
          value: 1,
          groupValue: _choose,
          onChanged: (v) {
            setState(() {
              _choose = v;
            });
          },
          title: Text('标题'),
          subtitle: Text('小标题'),
          secondary:
              Image.network("https://www.itying.com/images/flutter/1.png"),
        ),
        SizedBox(
          height: 10,
        ),
        RadioListTile(
          value: 2,
          groupValue: _choose,
          onChanged: (v) {
            setState(() {
              _choose = v;
            });
          },
          title: Text('标题'),
          subtitle: Text('小标题'),
          secondary: Icon(Icons.add),
        ),
        SizedBox(
          height: 10,
        ),
        RadioListTile(
          value: 3,
          groupValue: _choose,
          onChanged: (v) {
            setState(() {
              _choose = v;
            });
          },
          title: Text('标题'),
          subtitle: Text('小标题'),
          secondary: Icon(Icons.add),
          selected: _choose == 3, //让里面的内容颜色也跟着变
        )
      ],
    );
  }
}
